<?php

namespace App\Admin\Controllers;

use App\Models\DeviceType;
use App\Http\Controllers\Controller;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Widgets\Callout;
use Encore\Admin\Facades\Admin;
use Illuminate\Support\Facades\DB;
use Dcat\Admin\Form;

class DeviceTypeController extends Controller
{
    public function index(Content $content)
    {
        return $content
            ->header('公司列表')
            ->description()
//            ->body(Callout::make('即将在下个版本发布，敬请期待~'))
            ->body($this->grid());
    }

    protected function grid()
    {
        return new Grid(new DeviceType(), function (Grid $grid) {
            $grid->showColumnSelector();
            $grid->column('dtypeId','ID');
            $grid->column('typename','类型名称')->limit(50);
            $grid->column('remark','类型说明');
            $grid->column('created_at','创建时间');
            // 启用边框模式
            $grid->withBorder();
            $grid->fixColumns(2);
            //显示详情按钮
            $grid->disableViewButton();
            // $grid->showViewButton();
            //操作按钮
            $grid->showActions();
            // $grid->disableActions();
            // $grid->disableBatchDelete();
            $grid->showCreateButton();
            // 禁用详情按钮
            // $grid->disableViewButton();
            // 显示详情按钮
            // $grid->showViewButton();
            // 禁用编辑按钮
            // $grid->disableEditButton();
            // 显示编辑按钮
            $grid->showEditButton();
            // 禁用快捷编辑按钮
            $grid->disableQuickEditButton();
            // 显示快捷编辑按钮
            // $grid->showQuickEditButton();
            // 设置弹窗宽高，默认值为 '700px', '670px'
            $grid->setDialogFormDimensions('50%', '50%');
            // 禁用删除按钮
            $grid->disableDeleteButton();
            // 显示删除按钮
            // $grid->showDeleteButton();
        });
    }
    public function update($id){
        return $this->form()->update($id);
    }
    public function store(){
        return $this->form()->store();
    }

    public function create(Content $content){
        return $content
            ->title('新建类型')
            ->description('创建')
            // ->body($this->buildPreviewButton())
            // ->body($this->newline())
            ->body($this->form());
    }
    public function form(){
        return Form::make(new DeviceType(), function (Form $form) {
            $form->block(8, function (Form\BlockForm $form) {
                // 设置标题
                $form->title('基本设置');
                // 显示底部提交按钮
                $form->showFooter();
                // 设置字段宽度
                $form->width(9, 2);
                $form->column(6, function (Form\BlockForm $form) {
                    $form->text('typename','类型名称')->required();
                    $form->text('remark','类型说明');
                    $form->switch('switch', '是否有层级')->default(0);
                });
            });
        });
    }


    public function edit($id,Content $content){
        return $content
            ->title('类型编辑')
            ->description('编辑')
            // ->body($this->buildPreviewButton())
            // ->body($this->newline())
            ->body($this->form()->edit($id));
    }
}
